package cn.dodgeball.java;

import cn.dodgeball.util.Const;
import cn.dodgeball.util.PClass;


import javax.swing.*;

public class GamePanel extends JPanel {
    SquarePanel squarePanel = new SquarePanel();
    GameOver gameOver = new GameOver();

    public GamePanel() {
        this.init();
    }

    public void init() {
        setOpaque(false);
        setVisible(false);
        setSize(Const.FRAME_WIDTH, Const.FRAME_WIDTH);
        setLayout(null);

        JLayeredPane layeredPane = new JLayeredPane();
        layeredPane.setSize(Const.FRAME_WIDTH, Const.FRAME_HEIGHT);
        layeredPane.setLayout(null);
        JPanel gameOverPanel = new JPanel();
        gameOverPanel.setSize(getWidth(),getHeight());
        gameOverPanel.setLayout(null);
        gameOverPanel.setOpaque(false);
        gameOverPanel.add(gameOver);
        layeredPane.add(squarePanel, 0);
        layeredPane.add(gameOver,1);

        add(layeredPane);
    }

    public void start() {
        Const.startTime = System.currentTimeMillis();
        Const.isGaming = true;
        Const.isGold = true;
        gameOver.setVisible(false);
        squarePanel.start();
        setVisible(true);
    }

    public void gameOver(){
        squarePanel.close();
        gameOver.start();
    }

    public void close() {
        setVisible(false);
        squarePanel.close();
        PClass.facePanel.setVisible(true);
    }
}
